<%
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", -1); //prevents caching at the proxy server
%>
<%@page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*"%>
<%@ include file="Connections/conDB.jsp" %>
<% int validaSession = 2; %>
<%@ include file="Connections/session.jsp" %>

<%
String[] parId_unid = request.getParameterValues("cbId_unidad");
String parId_lib = request.getParameter("id_lib");
String parModalidad = request.getParameter("modalidad");

//out.print(parId_lib+"<br>"+parModalidad);

/*for (int x=0; x < parId_unid.length; x++) {
	out.print(parId_unid[x]+"<br>");
}*/

Driver DriverRs = (Driver)Class.forName(MM_conDB_DRIVER).newInstance();
Connection ConnRs = DriverManager.getConnection(MM_conDB_STRING,MM_conDB_USERNAME,MM_conDB_PASSWORD);
String query ="";
PreparedStatement StatementRs =null;

if (parId_unid[0]!=null && !parId_unid[0].equals("") && parId_lib!=null && !parId_lib.equals("") && parModalidad!=null && parModalidad.equals("asociar")) {
	for (int x=0; x < parId_unid.length; x++) {
		query = "UPDATE unidad SET "+
				"liberacion = "+parId_lib+" "+
				"WHERE id_unidad = "+parId_unid[x];
		//out.print(query+"<br>");
		StatementRs = ConnRs.prepareStatement(query);
	    StatementRs.executeUpdate();
	}
} // fin asociar

if (parId_unid[0]!=null && !parId_unid[0].equals("") && parId_lib!=null && !parId_lib.equals("") && parModalidad!=null && parModalidad.equals("desasociar")) {
	for (int x=0; x < parId_unid.length; x++) {
		query = "UPDATE unidad SET "+
				"liberacion = -1 "+
				"WHERE id_unidad = "+parId_unid[x];
		//out.print(query+"<br>");
		StatementRs = ConnRs.prepareStatement(query);
	    StatementRs.executeUpdate();
	}
} // fin asociar

	out.print("<script>");
	out.print("window.opener.location.reload();");
	out.print("window.close();");
	out.print("</script>");

ConnRs.close();

%>
<html>
<head>
<title>CIMA v2 - Asociar Liberacion</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">

</body>
<HEAD>
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
</HEAD>
</html>
